package com.i8office.android.zhihuixinwu.module.model;

import com.cyan.tools.callback.RequestCallback;
import com.i8office.android.zhihuixinwu.app.App;
import com.i8office.android.zhihuixinwu.bean.Preview;
import com.i8office.android.zhihuixinwu.module.contract.PreviewContract;
import com.i8office.android.zhihuixinwu.util.OfficeSubscriber;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by pc on 2018/7/7.
 */

public class PreviewModel implements PreviewContract.Model {
    @Override
    public Disposable getPreview(final RequestCallback<Preview> callback, String id) {
        return App.getComponent().getAPIService().getPreviewResult(id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Preview>(callback));
    }

    @Override
    public Disposable getNewsPreviewResult(RequestCallback<Preview> callback, String id) {
        return App.getComponent().getAPIService().getNewsPreviewResult(id).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Preview>(callback));
    }

    @Override
    public Disposable getExcelPreview(RequestCallback<Preview> callback, String id) {
        return App.getComponent().getAPIService().getExcelPreview(id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Preview>(callback));
    }

    @Override
    public Disposable getCebPreview(RequestCallback<Preview> callback, String id) {
        return App.getComponent().getAPIService().getCebPreview(id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Preview>(callback));
    }
}
